/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * RunningStatusPanel.java
 *
 * Created on 2009-1-17, 22:36:24
 */

package com.guzzservices.easydomain.ui.panel;

import com.guzzservices.easydomain.logic.DomainManager;
import com.guzzservices.easydomain.logic.domain.DynamicDomainChangeListener;
import com.guzzservices.easydomain.ui.frame.DDSProjectApp;
import java.awt.Color;

/**
 *
 * @author Administrator
 */
public class RunningStatusPanel extends javax.swing.JPanel {

    private Thread updateThread ;

    /** Creates new form RunningStatusPanel */
    public RunningStatusPanel() {
        initComponents();
        initContent() ;

        DomainManager.getDomainManager().addDynamicDomainChangeListener(new
            DynamicDomainChangeListener(){

            public void notifyDomainChanged() {
                refreshView() ;
            }
        
            }
        );
    }

    private void initContent(){
        htmlPane = new com.guzzservices.easydomain.ui.panel.URLLoadAndShowPanel("http://share.guzzservices.com/easydomain/status/?v=" + DomainManager.getDomainManager().softwareVersion + "&source=client");
        htmlPane.setBackground(Color.white) ;
        jScrollPane1.setViewportView(htmlPane);

        DDSProjectApp.registerURLLoadAndShowPanel(htmlPane) ;

        updateThread = new Thread(
                new Runnable(){
                    public void run() {
                        while(true){
                            synchronized(this){
                                RunningStatusPanel.this.refreshView();

                                try {
                                    wait(1000 * 60);
                                } catch (InterruptedException ex) {

                                }
                            }
                        }
                    }
                }
         ) ;

         updateThread.start();
    }

    public void refreshView(){
        DomainManager dm = DomainManager.getDomainManager() ;
        
        String s = "系统已运行：" + dm.getOnlineTime() + "；" ;
        int tc = dm.getTopDomains().size() ;
        int dc = dm.getActiveDynamicDomainCount() ;

        s = s + "主域名：" + tc + "个；" ;
        s = s + "当前运行动态域名：" + dc + "个；" ;

        productStatusSwingLabel.setText(s) ;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        productStatusSwingLabel = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(com.guzzservices.easydomain.ui.frame.DDSProjectApp.class).getContext().getResourceMap(RunningStatusPanel.class);
        setBackground(resourceMap.getColor("Form.background")); // NOI18N
        setName("Form"); // NOI18N

        jPanel1.setBackground(resourceMap.getColor("jPanel1.background")); // NOI18N
        jPanel1.setForeground(resourceMap.getColor("jPanel1.foreground")); // NOI18N
        jPanel1.setName("jPanel1"); // NOI18N
        jPanel1.setPreferredSize(new java.awt.Dimension(651, 25));

        productStatusSwingLabel.setFont(resourceMap.getFont("productStatusSwingLabel.font")); // NOI18N
        productStatusSwingLabel.setForeground(resourceMap.getColor("productStatusSwingLabel.foreground")); // NOI18N
        productStatusSwingLabel.setText(resourceMap.getString("productStatusSwingLabel.text")); // NOI18N
        productStatusSwingLabel.setName("productStatusSwingLabel"); // NOI18N

        org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .add(productStatusSwingLabel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(productStatusSwingLabel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 26, Short.MAX_VALUE)
        );

        jScrollPane1.setBackground(resourceMap.getColor("jScrollPane1.background")); // NOI18N
        jScrollPane1.setName("jScrollPane1"); // NOI18N

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 689, Short.MAX_VALUE)
            .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 689, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(jPanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 26, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 434, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel productStatusSwingLabel;
    // End of variables declaration//GEN-END:variables
    private com.guzzservices.easydomain.ui.panel.URLLoadAndShowPanel htmlPane ;
}
